using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_FacilityTypeManagement : admin_BaseUserControl
{
    FacilityTypeDAO daoFacType = new FacilityTypeDAO();
    FacilityType facType = new FacilityType();
    public string GetImageURL()
    {
        return facType.ImageURL;
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        ActiveAccording = "facility";
        if (Request["mode"] == "1")
        {
            lnkAdd.Visible = false;
            lnkUpdate.Visible = true;
            lnkDelete.Visible = true;
            try
            {
                int id = int.Parse(Request["id"]);
                facType.Id = id;
                facType = daoFacType.GetFacilityType(id);
                txtName.Text = facType.Name;
                txtDescription.Text = facType.Description;
                chkState.Checked = facType.State;
                FCKeditor1.Value = facType.Article;


            }
            catch (Exception ex)
            {
                Response.Redirect("Default.aspx?ctrl=fac_type_list");
            }
        }
        else
        {
            lnkAdd.Visible = true;
            lnkUpdate.Visible = false;
            lnkDelete.Visible = false;
        }
    }
    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        if (daoFacType.Delete(facType.Id) > 0)
        {
            ShowMessage("Facility type has been removed");
            lnkDelete.Visible = false;
            lnkUpdate.Visible = false;
            lnkAdd.Visible = true;
        }
        else ShowMessage("Error has occured when trying to remove current facility type");
    }
    protected void lnkAdd_Click(object sender, EventArgs e)
    {
        facType.Name = txtName.Text;
        facType.Description = txtDescription.Text;
        facType.ImageURL = Request["txtImage"];
        facType.Article = FCKeditor1.Value;
        facType.State = chkState.Checked;
        facType.ModifiedDate = DateTime.Now;
        facType.ModifiedBy = 1;
        if (daoFacType.Insert(facType) > 0)
        {
            ShowMessage("New facility type has been added successfully");
            lnkAdd.Visible = false;
            lnkUpdate.Visible = true;
            lnkDelete.Visible = true;

        }
        else ShowMessage("Error: Some error has occured when trying to add new facility type.");
    }

    protected void lnkUpdate_Click(object sender, EventArgs e)
    {
        facType.Name = txtName.Text;
        facType.Description = txtDescription.Text;
        facType.ImageURL=Request["txtImage"];
        facType.State = chkState.Checked;
        facType.Article = FCKeditor1.Value;
        facType.ModifiedDate = DateTime.Now;
        facType.ModifiedBy = 1;
        if (daoFacType.Update(facType) > 0)
        {
            ShowMessage("Updated successfully");
        }
        else ShowMessage("Error: Error occured when trying to update facily type information");
    }
}
